<template>
  <div class="ele-body">
    <el-card shadow="never">
      <!-- 搜索表单 -->
      <!-- <role-search @search="reload" /> -->
      <!-- 数据表格 -->

      <ele-pro-table ref="table"
                     :columns="columns"
                     :datasource="datasource"
                     :selection.sync="selection"
                     tool-class="ele-toolbar-form"
                     row-key="id">
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <!-- <el-button size="small"
                     type="primary"
                     icon="el-icon-plus"
                     class="ele-btn-icon"
                     @click="openEdit()">
            添加
          </el-button> -->
        </template>

        <template v-slot:content="{ row }">
          <div v-html="row.content"></div>
        </template>
        <!-- <template v-slot:status="{ row }">
          {{ orderStatusFn(row.status) }}
        </template> -->
        <!-- 状态列 -->
        <template v-slot:sex="{ row }">
          {{ row.sex==0?'性别不限':row.sex==1?'男':'女' }}
        </template>
        <template v-slot:level="{ row }">
          <div>
            {{ row.level==0?'普通用户':'vip用户' }}
          </div>
        </template>
        <template v-slot:img="{ row }">
          <el-link type="primary"
                   :underline="false"
                   icon="el-icon-view"
                   @click="openInvoice(row.img)">
            查看
          </el-link>

        </template>
        <template v-slot:name="{ row }">
          <div v-if="row.name">
            <div class="realNameStyle">
              <img class="avaterName"
                   :src="row.head_img"
                   alt="" />
              <span>{{ row.name }}</span>
            </div>
          </div>
          <div v-else>-----</div>
        </template>
        <template v-slot:nickname="{ row }">
          <div v-if="row.nickname">
            <div class="realNameStyle">
              <img class="avaterName"
                   :src="row.avatar"
                   alt="" />
              <span>{{ row.nickname }}</span>
            </div>
          </div>
          <div v-else>-----</div>
        </template>
        <template v-slot:state="{ row }">
          <el-switch :active-value="1"
                     :inactive-value="0"
                     v-model="row.state"
                     @change="editStatus(row)" />
        </template>
        <!-- <template v-slot:sort="{ row }">
			<i class="sort-handle el-icon-rank ele-text-secondary"
			   style="cursor: move"></i>
			<div v-if="false">{{ row }}</div>
		  </template> -->
        <!-- 操作列 -->
        <template v-slot:action="{ row }">
          <el-link v-if="row.status!=4"
                   type="primary"
                   :underline="false"
                   icon="el-icon-edit"
                   @click="openEdit(row)">
            修改
          </el-link>

        </template>

      </ele-pro-table>
    </el-card>
    <el-dialog title="群二维码"
               style="text-align: center"
               :visible.sync="dialogVisibles"
               width="25%">
      <img class="imgCode"
           :src="qRCode"
           alt="" />
      <span slot="footer"
            class="dialog-footer">
        <el-button type="primary"
                   @click="dialogVisibles = false">确 定</el-button>
      </span>
    </el-dialog>
    <Camilist :data="current1"
              :drawerEditBoolen.sync="drawerEditBoolen1"
              @done="reload" />
    <!-- 编辑弹窗 -->
    <role-edit :data="current"
               :drawerEditBoolen.sync="drawerEditBoolen"
               @done="reload" />

    <!-- 权限分配弹窗 -->
  </div>

</template>
	  <script>


// import RoleSearch from './components/role-search';
// import Sortable from 'sortablejs';
import RoleEdit from './components/role-edit';
import { carouselList } from './constant/constant';
import Camilist from './components/Camilist';
import { navigationList, navigationEdit } from '@/api/basicConfiguration/menu';

import { communityList, updateSort, updateCommunityStatus } from '@/api/communityManagement/index'
// import {
//   sitecCategoriesDelete,
//   siteCategoriesList,
//   siteCategoriesModify,
//   siteCategoriesDetail,
//   siteBatchCategoriesDelete
// } from '@/api/serviceManagement/categoriesList';
export default {
  name: 'Recharge',
  components: {
    // RoleSearch,
    RoleEdit,
    Camilist

  },
  data () {
    return {
      form: {
        number: 0
      },
      carouselList,
      // 表格列配置
      columns: [

        // {
        //   prop: 'id',
        //   label: '排序',
        //   sortable: 'custom',
        //   showOverflowTooltip: true,
        //   minWidth: 30,
        //   align: 'center',
        //   slot: 'sort'
        // },

        {
          columnKey: 'index',
          type: 'index',
          label: '序号',
          width: 60,
          align: 'center',
          showOverflowTooltip: true,

        },
        {
          prop: 'new_name',
          label: '导航栏名字(新)',
          sortable: 'custom',

          align: 'center',
          showOverflowTooltip: true,
        },
        {
          prop: 'old_name',
          label: '导航栏名字(旧)',
          sortable: 'custom',

          align: 'center',
          showOverflowTooltip: true,
        },
        {
          prop: 'state',
          label: '是否开启',
          align: 'center',
          sortable: 'custom',

          showOverflowTooltip: true,
          slot: 'state'

        },


        // {
        //   prop: 'create_time',
        //   label: '创建时间',
        //   align: 'center',
        //   sortable: 'custom',
        //   showOverflowTooltip: true,
        //   formatter: (_row, _column, cellValue) => {
        //     return this.$util.toDateString(cellValue, 'yyyy-MM-dd HH:mm');
        //   }
        // },
        {
          columnKey: 'action',
          label: '操作',
          width: 305,
          align: 'center',
          resizable: false,
          slot: 'action',
          hideInSetting: true,
          showOverflowTooltip: true,
          fixed: 'right'

        }
      ],
      // 表格选中数据
      selection: [],
      // 当前编辑数据
      current: null,
      current1: null,
      drawerEditBoolen: false,
      // 是否显示编辑弹窗
      drawerEditBoolen1: false,
      // 是否显示导入弹窗
      showAuth: false,
      showChoose: false,
      dialogVisible: false,
      levelId: null,
      dialogVisibles: false,
      qRCode: ''

    };
  },
  mounted () {

  },
  activated () {
    this.reload();
  },
  computed: {
    orderStatusFn: function () {
      return function (status) {

        let orderStatus = '';
        // status订单状态（0.待付款 1.待接单 2.已接单 3.服务中 4.已完成 5.已取消/退款)
        orderStatus =
          status == 0 ? '全部' : status == 1 ? '待审核' : status == 2 ? '上架' : status == 3 ? '下架' : status == 4 ? '删除' : '驳回';

        return orderStatus;
      };
    },

  },

  methods: {

    async openCami (row) {
      console.log(row);
      if (row?.id) {
        // const res = await siteCategoriesDetail(row.id);

        this.current1 = row;
        // 用户余额管理
        this.drawerEditBoolen1 = !this.drawerEditBoolen1;
      } else {
        this.drawerEditBoolen1 = !this.drawerEditBoolen1;
        this.current = null;
      }
    },
    save (row, status) {

      this.loading = true;

      const saveOrUpdate = updateCommunityStatus
      saveOrUpdate({
        status: status,
        id: row.id,

      })
        .then((msg) => {
          console.log(msg);
          this.loading = false;
          this.$message.success(msg.message);
          this.reload()

        })
        .catch((e) => {
          this.loading = false;
          this.$message.error(e.message);
        });



    },
    openInvoice (imgStr) {
      // 点击按钮预览图片

      console.log(imgStr);
      this.dialogVisibles = true;
      this.qRCode = imgStr;
    },

    // rowDrop () {
    //   const tbody = document.querySelector('.el-table__body-wrapper tbody');
    //   const _this = this;
    //   Sortable.create(tbody, {
    //     forceFallback: true,
    //     dragClass: 'drag',
    //     delay: 100,
    //     animation: 1000,
    //     onEnd ({ newIndex, oldIndex }) {
    //       console.log(newIndex);
    //       console.log(oldIndex);
    //       //更换表格数据 后续拖动坐标才会正确
    //       let data = _this.$refs.table.getData();

    //       let nid = data[newIndex].id;
    //       let oid = data[oldIndex].id;

    //       const currRow = data.splice(oldIndex, 1)[0];
    //       data.splice(newIndex, 0, currRow);

    //       console.log(data);

    //       //   sortChange(data)
    //       //     .then((msg) => {

    //       //     })
    //       //     .catch((e) => {
    //       //       _this.$refs.table.reload();
    //       //     });

    //       //去数据库更换排序

    //       console.log(_this.$refs.table.getData());
    //     }
    //   });
    // },

    /* 显示编辑 */
    async openEdit (row) {
      console.log(row);
      if (row?.id) {
        // const res = await siteCategoriesDetail(row.id);

        this.current = row;
        // 用户余额管理
        this.drawerEditBoolen = !this.drawerEditBoolen;
      } else {
        this.drawerEditBoolen = !this.drawerEditBoolen;
        this.current = null;
      }
    },
    /* 表格数据源 */
    datasource ({ page, limit, where }) {
      return navigationList({
        page,
        limit,
        ...where,

      });
    },

    /* 刷新表格 */
    reload (where) {
      this.$refs.table.reload({ page: 1, where: where });
    },



    /* 更改状态 */
    editStatus (row) {
      const loading = this.$loading({ lock: true });
      navigationEdit({
        id: row.id,
        state: row.state ? 1 : 0,
        order: row.order,
        newName: row.new_name

      })
        .then((msg) => {
          console.log(msg)
          loading.close();
          this.$message.success(msg);
          this.reload();
        })
        .catch((e) => {
          loading.close();

          this.$message.error(e);
        });
    },

    /* 显示分配权限 */
    openAuth (row) {
      this.current = row;
      this.showAuth = true;
    },
    /* 删除 */
    // remove (row) {
    //   const loading = this.$loading({ lock: true });
    //   upClassify({
    //     id: row.id,
    //     status: 0,

    //   })
    //     .then((msg) => {
    //       loading.close();
    //       this.$message.success(msg);
    //       this.reload();
    //     })
    //     .catch((e) => {
    //       loading.close();
    //       this.$message.error(e.message);
    //     });
    // },
    /* 批量删除 */
    // removeBatch () {
    //   if (!this.selection.length) {
    //     this.$message.error('请至少选择一条数据');
    //     return;
    //   }
    //   console.log(this.selection);
    //   this.$confirm('确定要删除选中的信息吗?', '提示', {
    //     type: 'warning'
    //   })
    //     .then(() => {
    //       const loading = this.$loading({ lock: true });
    //       console.log(this.selection.map((d) => d.id));
    //       siteBatchCategoriesDelete(this.selection.map((d) => d.id))
    //         .then((msg) => {
    //           loading.close();
    //           this.$message.success(msg);
    //           this.reload();
    //         })
    //         .catch((e) => {
    //           loading.close();
    //           this.$message.error(e.message);
    //         });
    //     })
    //     .catch(() => { });
    // }
  }
};
	  </script>
	  
  <style lang="less">
.imgCode {
  width: 100%;
  height: 250px;
}
.categoryImages {
  width: 50px;
  height: 50px;
}
.realNameStyle {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  .avaterName {
    width: 32px;
    height: 32px;
    border-radius: 32px;
    vertical-align: middle;
    margin-right: 5px;
  }
}
</style>
	  